local skel = fk.CreateSkill {
  name = "emo__dazheng",
  tags = {Skill.Compulsory},
}

Fk:loadTranslationTable{
  ["emo__dazheng"] = "大征",
  [":emo__dazheng"] = "锁定技，你使用【杀】时，将此牌洗入牌堆并检索一张【闪】，改为对目标使用其中所有【杀】。",

  ["$emo__dazheng1"] = "抄窃边陲，挤拒王师，刑兹无赦！",
  ["$emo__dazheng2"] = "日月所照风雨所沾，孰非我臣？",
}

skel:addEffect(fk.CardUsing, {
  anim_type = "offensive",
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(skel.name) and data.card.trueName == "slash"
    and player.room:getCardArea(data.card) == Card.Processing
    and data.tos and #data.tos > 0
    and not (data.extra_data and data.extra_data.emo__dazheng)
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local tos = table.simpleClone(data.tos)
    data.nullifiedTargets = table.simpleClone(room.players)
    room:moveCards({
      ids = Card:getIdList(data.card),
      toArea = Card.DrawPile,
      moveReason = fk.ReasonPut,
      skillName = skel.name,
      proposer = player,
      drawPilePosition = math.random(1 + #room.draw_pile)
    })
    local ids = {}
    while #room.draw_pile > 0 and player:isAlive() do
      local cid = room:getNCards(1)[1]
      table.insertIfNeed(ids, cid)
      room:moveCardTo(cid, Card.Processing, nil, fk.ReasonJustMove, skel.name)
      if Fk:getCardById(cid).trueName == "jink" then break end
      room:delay(100)
    end
    for _, id in ipairs(ids) do
      local card = Fk:getCardById(id)
      if room:getCardArea(id) == Card.Processing and card.trueName == "slash" then
        tos = room:deadPlayerFilter(tos)
        if #tos == 0 then break end
        local targets = table.filter(tos, function (p)
          return not player:isProhibited(p, card)
        end)
        if #targets > 0 then
          room:useCard{
            card = card, from = player, tos = targets, extraUse = true,
            extra_data = {emo__dazheng = true},
          }
        end
      end
    end
    room:cleanProcessingArea(ids)
  end,
})

return skel
